<?php
    #-------------------------------------------------------------#
	# This file is part of the Kumomado - Virtual Window Platform #
	# for PHP. (c) 2009 Tsai, Min Che <tirme0812@gmail.com>       #
	# Please visit http://www.kumomado.org/ for more information. #
	#                                                             #
	# This software is licensed under the GNU License v3. Please  #
	# view the LICENSE file for the full text of this license.    #
    #-------------------------------------------------------------#

	Kumomado::load('MVCHelper.KumomadoAbstractMVCHelper');
	/**
	 * @package libraries/platform/
	 * @author Tsai, Min Che
	 * @version 1.0
	 */
	class KumomadoPlatform extends KumomadoAbstractMVCHelper {
		public $class;
		public $method;
		/**
		 * Construct
		 */
		public function __construct($class, $method = 'main') {
			$this->class = ucfirst(strtolower($class));
			$this->method = Kumomado::config('main')->ActionPrefix.$method;
			$this->init($this->loadController(), $this->loadModel(), $this->loadView());
		}
		protected function loadModel() {
			$model_name = $this->class.'Model';
			$model_file = KUMOMADO_PLATFORM_PATH.'model'.DIRECTORY_SEPARATOR.$model_name.'.class.php';
			if (file_exists($model_file)) {
				include_once $model_file;
				return new $model_name;
			} else {
				throw new KumomadoPlatformException('The controller file cloud not loaded. ('.$model_file.')');
			}
		}
		protected function loadController() {
			$controller_name = $this->class.'Controller';
			$controller_file = KUMOMADO_PLATFORM_PATH.'controller'.DIRECTORY_SEPARATOR.$controller_name.'.class.php';
			if (file_exists($controller_file)) {
				include_once $controller_file;
				return new $controller_name;
			} else {
				throw new KumomadoPlatformException('The controller file cloud not loaded. ('.$controller_file.')');
			}
		}
		protected function loadView() {
			$view_name = $this->class.'View';
			$view_file = KUMOMADO_PLATFORM_PATH.'view'.DIRECTORY_SEPARATOR.$view_name.'.class.php';
			if (file_exists($view_file)) {
				include_once $view_file;
				return new $view_name;
			} else {
				throw new KumomadoPlatformException('The view file cloud not loaded. ('.$view_file.')');
			}
		}
	}
?>